package com.feihong.yw189.view;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;

public class MyListView extends ListView {

    public final static float SCALE = 1.2f;
    private View targetView;

    public MyListView(Context context) {
        super(context);
    }

    public MyListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {

            case MotionEvent.ACTION_DOWN:
                int XDonw = (int) ev.getX();
                int YDonw = (int) ev.getY();
                int position = pointToPosition(XDonw, YDonw);
                if (position != -1) {
                    targetView = getChildAt(position);
                    targetView.setScaleY(SCALE);
                    targetView.setScaleX(SCALE);
                    targetView.setPadding(0, 5, 0, 5);
                }

                break;
            case MotionEvent.ACTION_UP:
                if (targetView != null) {
                    targetView.setScaleY(1);
                    targetView.setScaleX(1);
                    targetView.setPadding(0, 0, 0, 0);
                }
                break;
        }

        return super.onTouchEvent(ev);

    }
}